//导入父类
import defaultConfig from './default-option'
//仪表盘的默认配置
const gaugeDefaultOptions = {
  radius: '75%',
  clockwise: true,
  title: {
    show: true,
    offsetCenter: [0, '-40%'],
    fontWeight: 'normal',
    fontSize: 18
  },
  detail: {
    show: true,
    color: 'auto',
    fontWeight: 'normal',
    fontSize: 15
  }
}

export default class OptionGauge extends defaultConfig {
  constructor(otherOption = {}, data = [], showData = []) {
    //将主题传给父类
    super()
    //删除转换图形配置
    delete this.defaultConfig.toolbox.feature.magicType
    //删除xAxis.data属性（以防止报错）
    delete this.defaultConfig.xAxis.data
    //合并||重新设置默认配置
    this.option = this.setNewStyle(this.setNewStyle({ tooltip: { trigger: 'item', axisPointer: { type: 'none' } } }, otherOption), this.defaultConfig)
    //给data添加label标签和设置type为radar
    this.option.series = data.map(item => this.setNewStyle({ label: this.label }, this.setNewStyle({ type: 'gauge' }, item)))
    //添加雷达图的默认配置
    this.option.series = this.option.series.map(item => {
      this.setNewStyle(gaugeDefaultOptions, item)
      return item
    })
  }
  //设置仪表盘显示的名称
  setGaugeName = (option, func) => {
    option.series.forEach(item => {
      item.detail.formatter = func
    })
  }
}